package com.atgm.mall.gmmailmember.controller;

import com.atgm.common.utils.R;
import com.atgm.mall.gmmailmember.entity.MemberCollectArticleEntity;
import com.atgm.mall.gmmailmember.service.MemberCollectArticleService;
import com.atgm.mall.gmmailmember.vo.resp.ArticleCollectRespVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("gmmallmember/membercollectarticle")
public class MemberCollectArticleController {

    @Autowired
    private MemberCollectArticleService memberCollectArticleService;

    /**
     * 获取用户的收藏数量
     * @param memberId
     * @return
     */
    @GetMapping("/getCollectCount/{memberId}")
    public R getCollectCountByMemberId(@PathVariable("memberId") Long memberId) {
        Integer count = memberCollectArticleService.queryCollectCountByMemberId(memberId);
        return R.ok().setData(count);
    }

    /**
     * 用户收藏文章
     * @param memberCollectArticleEntity
     * @return
     */
    @PostMapping("/collectArticle")
    public R collectArticle(@RequestBody MemberCollectArticleEntity memberCollectArticleEntity) {
        memberCollectArticleService.saveMemberCollectArticle(memberCollectArticleEntity);
        return R.ok();
    }

    /**
     * 获取收藏该文章的用户信息
     * @param articleId
     * @return
     */
    @GetMapping("/getCollectMember/{articleId}")
    public R getColllectMember(@PathVariable("articleId") Long articleId) {
        ArticleCollectRespVo articleCollectRespVo = memberCollectArticleService.queryCollectMemberByArticleId(articleId);
        return R.ok().setData(articleCollectRespVo);
    }

    @GetMapping("/isCollectArticle/{articleId}/{memberId}")
    public R isCollectArticle(@PathVariable("articleId") Long articleId, @PathVariable("memberId") Long memberId) {
        Integer flag = memberCollectArticleService.haveCollectArticle(articleId, memberId);
        return R.ok().setData(flag);
    }

}
